#ifndef SIMPLEBYTEBUFFER_H
#define SIMPLEBYTEBUFFER_H


//定义一个内存块大小 在扩充缓冲区的时候 一次扩充该大小空间
#define BLOCKSIZE 32 * 1024

class SimpleByteBuffer
{
public:
    SimpleByteBuffer();
    ~SimpleByteBuffer();

    //写入数据到缓冲区
    bool Put(const unsigned char * buf, const unsigned int size);
    //缓冲区可读取数据起始地址
    const unsigned char * RBuf();
    //缓冲区可写入起始地址
    char * WBuf();
    //检查缓冲区中是否有有效数据
    bool CanRead() const;
    //获取缓冲区中可读数据的大小
    unsigned int CanReadSize() const;
    //偏移读取地址
    void MoveROffset(const unsigned int size);
    //获取缓冲区可写入数据大小
    unsigned int CanWriteSize() const;
    //偏移写入地址
    void MoveWOffset(const unsigned int size);
    //重置缓冲区数据
    void Reset();
    //返回缓冲区最大大小
    unsigned int MaxSize() const;
    //整理缓冲区 清除废弃数据 解放缓冲区 不足则 扩充缓冲区大小
    void TidyBuf(const unsigned int size);

private:
    //缓冲区大小
    unsigned int m_MaxSize;
    //可读偏移地址
    unsigned int m_Offset;
    //可写偏移地址
    unsigned int m_CurrOffset;
    //缓冲区
    unsigned char * m_Buffer;
};

#endif
